<template>
  <el-dialog
    :close-on-click-modal="false"
    title="调整计划员"
    v-model="visible"
    align-center
    width="600px"
    destroy-on-close
  >
    <el-form-item label="计划员" class="mt-[16px]">
      <VCascader v-model="form.plan_user_id" placeholder="请选择人员" />
    </el-form-item>
    <template #footer>
      <el-button @click="handleClose(false)">取 消</el-button>
      <el-button type="primary" :loading="loading" @click="save"
        >确 定</el-button
      >
    </template>
  </el-dialog>
</template>
<script setup>
import { ElMessage } from "element-plus";
import { purchaseDemandSetPlan } from "../../api";
import { resMessage } from "@/utils/res";
const props = defineProps({
  options: { type: Object, default: () => ({}) },
});
const emit = defineEmits(["close", "success"]);
const loading = ref(false);
const visible = ref(false);
const form = ref({});
// 打开弹窗
const open = async (id) => {
  visible.value = true;
  form.value.dd_ids = id;
};
const save = async () => {
  if (!form.value?.plan_user_id) return ElMessage.warning("计划人员不能为空!");
  try {
    loading.value = true;
    const res = await purchaseDemandSetPlan(form.value);
    resMessage({
      res,
      success: () => {
        ElMessage.success("操作成功");
        handleClose(true);
      },
    });
  } finally {
    loading.value = false;
  }
};
const handleClose = (refresh) => {
  visible.value = false;
  form.value = {};
  emit("close");
  refresh && emit("success");
};
defineExpose({ open });
</script>
